package com.fromfuture.xuhuidoc.android.activity.mainframe;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.fromfuture.xuhuidoc.R;
import com.fromfuture.xuhuidoc.android.activity.DocCircleChatRoomActivity;
import com.fromfuture.xuhuidoc.android.adapter.DocRecycleViewAdapter;
import com.fromfuture.xuhuidoc.android.base.BaseFragment;
import com.fromfuture.xuhuidoc.android.customview.DividerItemDecoration;
import com.fromfuture.xuhuidoc.android.customview.MyItemAnimator;
import com.fromfuture.xuhuidoc.android.customview.MySearchView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hp on 2017/8/17.
 */

public class DocCircleFragment extends BaseFragment {

    private View rootview;

    public MySearchView mySearchView;

    private RecyclerView mRecyclerView;

    public DocCircleFragment() {
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootview=inflater.inflate(R.layout.fragment_doc_circle,container,false);
        init();
        return rootview;
    }

    private void init(){
        findViewById();
        recyclerView();
    }

    private void findViewById(){
        mySearchView= (MySearchView) rootview.findViewById(R.id.doc_search_view);
        mRecyclerView= (RecyclerView) rootview.findViewById(R.id.doc_recycle_view);
    }

    private void recyclerView(){
        int a=1;

        //添加分割线DividerItemDecoration.HORIZONTAL_LIST:垂直的线;
        // DividerItemDecoration.VERTICAL_LIST水平线
        //分割线DividerItemDecoration 在sdk下查找的
        mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
        mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.HORIZONTAL_LIST));

        //recyclerview动画：DefaultItemAnimator自带的
        mRecyclerView.setItemAnimator(new MyItemAnimator());

//        //线性布局管理器(垂直(ListView)，水平(Gallery))，替代ListView选择水平方向
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()
                , LinearLayoutManager.VERTICAL, false
        );

//        //九宫格式的布局(垂直方向替代的GridView)
//        //垂直方向参数2代表列数，水平方向代表行数
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false);
//        //给RcyclerVIew设置布局

        mRecyclerView.setLayoutManager(linearLayoutManager);

        final List<String> list = new ArrayList<String>();
        final List<Integer>listnum=new ArrayList<Integer>();
        for (int i = 0; i < 8; i++) {
            Log.e("=====", "======" + i);
            list.add("枫林社区一小风团队" + i );
            listnum.add(i);
        }
        final DocRecycleViewAdapter myAdapter = new DocRecycleViewAdapter(list,listnum, getActivity());
        //填充数据
        mRecyclerView.setAdapter(myAdapter);
        myAdapter.setmOnItemClickListener(new DocRecycleViewAdapter.onItemClickListener() {
            @Override
            public void onItemClickListener(int pos) {
                Log.e("======", "==点击了===" + pos);
                Intent intent=new Intent(getActivity(), DocCircleChatRoomActivity.class);
                startActivity(intent);

            }
        });
        myAdapter.setmOnItemLongClickListener(new DocRecycleViewAdapter.onItemLongClickListener() {
            @Override
            public void onItemLongClickListener(int pos) {
                Log.e("======", "==长按===" + pos);
                Toast.makeText(getActivity(),"==长按了===" + pos,Toast.LENGTH_SHORT).show();
                myAdapter.setNumChange(new DocRecycleViewAdapter.numChange() {
                    @Override
                    public void numChanges(int pos) {
                        //此时调用适配器中自己写的一个方法
                        myAdapter.nuchangShican(pos,33);
                    }
                });
                myAdapter.remove(pos);
            }
        });


    }


    public static class DocCircleBroadcast extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {

        }
    }




}
